<template>
  <div class="cartcontrol">
    <transition name="move">
      <div class="iconfont icon-remove_circle_outline" v-if="food.count>0" @click.stop="subFood"></div>
    </transition>
    <div class="cart-count" v-if="food.count>0">{{food.count}}</div>
    <div class="iconfont icon-add_circle" @click.stop="addFood"></div>
  </div>
</template>

<script>
import store from 'vuex'
export default {
  data() {
    return {};
  },
  props:{
    food:{
      type: Object,
      require: true
    }
  },
  methods: {
    addFood(){
      // 数据状态属于谁，谁就去更新，这里是通知需要更新状态
      this.$store.dispatch('addFoodCount', {food: this.food})
    },
    subFood(){
      this.$store.dispatch('subFoodCount', {food: this.food})
    }
  },
};
</script>
<style lang='less' scoped>
.cartcontrol {
  font-size: 0;
  .cart-decrease {
    display: inline-block;
    padding: 6px;
    line-height: 20px;
    font-size: 20px;
    color: rgb(0, 160, 220);
  }
  .icon-remove_circle_outline {
    display: inline-block;
    padding: 6px;
    line-height: 20px;
    font-size: 20px;
    color: #02a774;
    &.move-enter, &.move-leave-to{
      opacity: 0;
      transform: translateX(15px) rotate(180deg) ;
    }
    &.move-enter-active, &.move-leave-active{
      transition: all 0.5s;
    }
  }
  .cart-count {
    display: inline-block;
    vertical-align: top;
    width: 12px;
    padding-top: 6px;
    line-height: 20px;
    text-align: center;
    font-size: 10px;
    color: rgb(147, 153, 159);
  }
  .icon-add_circle {
    display: inline-block;
    padding: 6px;
    line-height: 20px;
    font-size: 20px;
    color: #02a774;
  }
}
</style>